public class Main {
    public static void main(String[] args) {
//        给定一个有序整型数组, 实现二分查找
        int[] arr = new int[]{1,2,3,4,5};
        for(int x: arr){
            System.out.print(x+" ");
        }
        System.out.println();
        search(arr,1);
        search(arr,2);
        search(arr,3);
        search(arr,4);
        search(arr,5);
        search(arr,6);
    }
    public static void search(int[] a, int find){
        int flag = 0;//假设没找到
        int left = 0;
        int right = a.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(a[mid] < find){
                left = mid + 1;
            }
            if(a[mid] > find){
                right = mid - 1;
            }
            if(a[mid] == find){
                flag = 1;
                break;
             }
        }
        if(flag == 1){
            System.out.println("找得到");
        }
        else{
            System.out.println("找不到");
        }
    }
}